{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9e4c925a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import sympy as sp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "855ffc72",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(arctan x)' = 1/(x**2 + 1)\n"
     ]
    }
   ],
   "source": [
    "# 定义变量x，表示对x求导\n",
    "x = sp.symbols('x', real=True)\n",
    "# y = arctan x\n",
    "y = sp.atan(x)\n",
    "# 对 y = arctan x 求导\n",
    "derivative = sp.diff(y, x)\n",
    "print('(arctan x)\\' = {}'.format(derivative))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2392f767",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(ln sec x)' = tan(x)\n"
     ]
    }
   ],
   "source": [
    "# y = ln sec x\n",
    "y = sp.ln(sp.sec(x))\n",
    "# 对 y = ln sec x 求导\n",
    "derivative = sp.diff(y, x)\n",
    "print('(ln sec x)\\' = {}'.format(derivative))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6ae7f67d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "D1 = 10*x**9 \n",
      "D2 = 90*x**8 \n",
      "D3 = 720*x**7 \n",
      "D4 = 5040*x**6 \n",
      "D5 = 30240*x**5 \n",
      "D6 = 151200*x**4 \n",
      "D7 = 604800*x**3 \n",
      "D8 = 1814400*x**2 \n",
      "D9 = 3628800*x \n",
      "D10 = 3628800 \n",
      "D11 = 0 \n"
     ]
    }
   ],
   "source": [
    "# 高阶导数\n",
    "\n",
    "# 定义变量x，表示对x求导\n",
    "x = sp.symbols('x')\n",
    "# y = x ^ 10\n",
    "y = x ** 10\n",
    "\n",
    "for n in range(1, 12):\n",
    "    # 计算n阶导数\n",
    "    D = sp.diff(y, x, n)\n",
    "    print('D%d = %s ' % (n, D))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cae7629e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
